package L623;

/**
 * @program: javase
 * @description:
 * @author: luolidong
 * @create: 2021-06-23 16:54
 * @version: 1.0
 */
public class Offer16 {
    public double myPow(double x, int n) {
        if(n==0||x==1.0){
            return 1.0;
        }
        if(n<0){
            n=-n;
            x=1/x;
        }
        double res=1.0;
        double a=x;
        while(n!=0){
            if(n%2==1){
                res*=a;
            }
            a=a*a;
            n>>=1;
        }
        return res;
    }

    public static void main(String[] args) {
        double v = new Offer16().myPow(2, 5);
        System.out.println(v);
    }
}
